import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class DialogDemo extends JFrame {
    JButton ok = new JButton("ok");
    JButton reset = new JButton("reset");

    public DialogDemo() {
        super("对话框");//super就是JFrame
        this.setSize(400, 300);

        Container c = this.getContentPane();
        c.setLayout(new FlowLayout());
        c.add(ok);
        c.add(reset);

        ok.addActionListener(new ActionListener() {//监听
            @Override
            public void actionPerformed(ActionEvent e) {
                JDialog jd = new JDialog(new JFrame(), "我是对话框", true);
                jd.setSize(200, 100);
                JButton add = new JButton();
                jd.getContentPane().add(new JLabel("你好"));
                jd.getContentPane().add(add);
                jd.getContentPane().setLayout(new FlowLayout());
                jd.setVisible(true);
                jd.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

            }
        });

        reset.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JDialog jd = new JDialog(new JFrame(),"我是对话框",true);
                jd.setSize(200,100);
                JButton add =new JButton();
                jd.getContentPane().add(new JLabel("退出"));
                jd.getContentPane().add(add);
                jd.getContentPane().setLayout(new FlowLayout());
                jd.setVisible(true);
                jd.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);

            }//监听
        });
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    public static void main(String[] args) {
        new  DialogDemo();
    }
}
